import urllib.request as ur
import urllib.parse as up
import json
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
try:
    word = input('请输入内容')
    data = {
        'kw':word
    }
    data_url = up.urlencode(data)
    request = ur.Request(
        url = 'https://fanyi.baidu.com/sug',
        data = data_url.encode('utf-8'),
    )
    response = ur.urlopen(request).read()
    # print(response)
    ret = json.loads(response)
    # print(ret)
    translate = ret['data'][0]['v']
    print(translate)
except:
    print('字符串过长')

